package jupitermouse.site.example.scala.window

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.windowing.time.Time

object WindowsReduceApp {
  def main(args: Array[String]): Unit = {

    val env = StreamExecutionEnvironment.getExecutionEnvironment

    val streamSet = env.socketTextStream("localhost",9999)

    import org.apache.flink.api.scala._

    //    通过传递进来的数字裂隙
        streamSet.flatMap(_.split(" "))
          .map(x => (1,x.toInt))
          .keyBy(0) //因为key都是1，所以所有元素都到里面执行
          .timeWindow(Time.seconds(5))
          .reduce((a,b) =>{
            println(a +"..."+b)
            (a._1,a._2+b._2)
          })
          .print()
          .setParallelism(1)


    env.execute("WindowsReduceApp")

  }
}
